﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using ENail.Domain.Core;
using ENail.Domain.Core.Contract.Services;
using ENail.Portal.Web.Models;

namespace ENail.Portal.Web.Controllers
{
    public class CustomerController: DUALController<CustomerListViewItem,
                                                       CustomerViewModel,
                                                       Customer>
    {
        private readonly ICustomerService _Customer;
        private readonly ITaskService _taskService;
        private TaskManager _taskManager;
        
        public CustomerController(ICustomerService Customer,ITaskService service)
            : base("CustomerList", 
                   "Customer", 
                   new CustomerListViewModelMapper(),
                   new CustomerViewModelMapper())
        {
            _Customer = Customer;
            _taskService = service;
            _taskManager=new TaskManager(_taskService);
        }

        protected override List<Customer> GetList()
        {
            return _Customer.GetAllActiveCustomers().ToList();
        }

        protected override Customer Get(int id)
        {
            return _Customer.GetCustomer(id);
        }

        protected override void Add(Customer domainModel)
        {
            User user = User as User;
            domainModel.NailSalon = user.NailSalon;

            _Customer.InsertCustomer(domainModel);
        }

        protected override void Update(Customer domainModel)
        {
            _Customer.UpdateCustomer(domainModel);
        }

        protected override void Delete(Customer domainModel)
        {
            _Customer.InActiveCustomer(domainModel);
        }
        #region View Task
        [ActionName("InitializeTask")]
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post | HttpVerbs.Head)]

        public ActionResult InitializeTask()
        {
            return PartialView("_Task", _taskManager.GetTaskModel());
        }
        #endregion
    }
}